package com.xyzh05.model;

import java.io.Serializable;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.OneToOne;
import javax.persistence.Table;
import javax.xml.bind.annotation.XmlRootElement;

import org.compass.annotations.Searchable;
import org.compass.annotations.SearchableId;
import org.compass.annotations.SearchableProperty;

@Entity
@Table(name="school")
@Searchable
@XmlRootElement
public class School extends BaseObject implements Serializable {
	private static final long serialVersionUID = -5595047945977672749L;
	
	private Long id;
    private String name;
    private String country;
    private String region;
    private String homepage;
    private String badge;
    private SchoolInfo schoolInfo = new SchoolInfo();

    @Id @GeneratedValue(strategy=GenerationType.AUTO) @SearchableId    
    public Long getId() {
        return this.id;
    }
    
    public void setId(Long id) {
        this.id = id;
    }
    
    @Column(name="name", nullable=false)
    @SearchableProperty
    public String getName() {
        return this.name;
    }
    
    public void setName(String name) {
        this.name = name;
    }
    
    @Column(name="country", nullable=false)
    @SearchableProperty
    public String getCountry() {
        return this.country;
    }
    
    public void setCountry(String country) {
        this.country = country;
    }
    
    @Column(name="region", nullable=false)
    @SearchableProperty
    public String getRegion() {
        return this.region;
    }
    
    public void setRegion(String region) {
        this.region = region;
    }
    
    @Column(name="homepage", length=65535)
    @SearchableProperty
    public String getHomepage() {
        return this.homepage;
    }
    
    public void setHomepage(String homepage) {
        this.homepage = homepage;
    }
    
    @Column(name="badge")
    @SearchableProperty
    public String getBadge() {
        return this.badge;
    }
    
    public void setBadge(String badge) {
        this.badge = badge;
    }

    @OneToOne(cascade=CascadeType.ALL, fetch=FetchType.LAZY, mappedBy="school")
    public SchoolInfo getSchoolInfo() {
		return schoolInfo;
	}

	public void setSchoolInfo(SchoolInfo schoolInfo) {
		this.schoolInfo = schoolInfo;
	}

	
    public School(){    	
    }
    
    public School(Long id, String name, String country){
    	this.id = id;
    	this.name = name;
    	this.country = country;
    }
	
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;

        School pojo = (School) o;

        if (name != null ? !name.equals(pojo.name) : pojo.name != null) return false;
        if (country != null ? !country.equals(pojo.country) : pojo.country != null) return false;
        if (region != null ? !region.equals(pojo.region) : pojo.region != null) return false;
        if (homepage != null ? !homepage.equals(pojo.homepage) : pojo.homepage != null) return false;
        if (badge != null ? !badge.equals(pojo.badge) : pojo.badge != null) return false;

        return true;
    }

    public int hashCode() {
        int result = 0;
        result = (name != null ? name.hashCode() : 0);
        result = 31 * result + (country != null ? country.hashCode() : 0);
        result = 31 * result + (region != null ? region.hashCode() : 0);
        result = 31 * result + (homepage != null ? homepage.hashCode() : 0);
        result = 31 * result + (badge != null ? badge.hashCode() : 0);

        return result;
    }

    public String toString() {
        StringBuffer sb = new StringBuffer(getClass().getSimpleName());

        sb.append(" [");
        sb.append("id").append("='").append(getId()).append("', ");
        sb.append("name").append("='").append(getName()).append("', ");
        sb.append("country").append("='").append(getCountry()).append("', ");
        sb.append("region").append("='").append(getRegion()).append("', ");
        sb.append("homepage").append("='").append(getHomepage()).append("', ");
        sb.append("badge").append("='").append(getBadge()).append("', ");
        sb.append("]");
      
        return sb.toString();
    }

}
